var app = getApp();
const pathUrl = app.globalData.pathUrl;
Page({

    /**
     * 页面的初始数据
     */
    data: {
        pathUrl: pathUrl,
        openId: '',
        queryResults: '',
        violationTimes: '',
        totalDeduction: '',
        totalFine: '',//总罚款
        list: ' ',
        array: ['同盾', '百融', '中诚信','黑瞳'],
        objectArray: [
            {
                id: 0,
                name: '同盾'
            },
            {
                id: 1,
                name: '百融'
            },
         
        ],
        index: 0,
        ocrName: '', //ocr姓名
        ocrSex: '', //ocr性别
        ocrNation: '', //ocr民族
        ocrBirth: '', //ocr出生
        ocrAddress: '', //ocr地址
        ocrIdNumber: '', //ocr身份证号
        ocrOffice: '', //ocr签发机关
        ocrValidityPeriod: '', //ocr有效期限
        cusIdValidfrom: '', //证件开始日期
        cusIdValidto: '', //证件结束日期
        brand: '', //品牌/车型
        plateNumber: '', //车牌号
        holder: '', //所有人
        dateIssue: '', //注册/发证日期
        nature: '', //使用性质
        address: '', //住址
        vinno: '', //车架号
        engineNumber: '', //发动机号
        residentialAddress: '', //居住地址
        telephone: '', //联系电话
        checkedValue: '', //婚姻情况
        spouseName: '', //配偶姓名
        spouseTelephone: '', //联系电话
        urgent: '', //紧急联系人
        urgentTelephone: '', //紧急联系人联系电话
        urgent2: '', //紧急联系人
        urgentTelephone2: '', //紧急联系人联系电话
        isSubmit: true, //防止重复提交
        guaranteeName: '', //担保人姓名
        guaranteeIdCard: '', //担保人身份照
        guaranteePhone: '', //担保人电话
        orderAmount: '', //金额
        pickerIndex: '3',//选择期数index
        orderPeriod: '36',//期数
        orderBy6: '',
        orderBy7: '',
        orderBy8: '',
        orderBy4: '',
        orderBy5: '',
        select: false,
        tihuoWay: '请选择查询接口'

    },
    bindShowMsg() {
        this.setData({
            select: !this.data.select
        })
    },
    mySelect(e) {
        var name = e.currentTarget.dataset.name
        this.setData({
            tihuoWay: name,
            select: false
        })
    },
    bindPickerChange: function (e) {
        console.log('picker发送选择改变，携带值为', e.detail.value)
        this.setData({
            index: e.detail.value
        })
    },
    bankcardno: function (e) {
        this.setData({
            bankcardno: e.detail.value
        })
    },
    mobile: function (e) {
        this.setData({
            mobile: e.detail.value
        })
    },
    //ocr名字赋值
    ocrNameInput: function (e) {
        this.setData({
            ocrName: e.detail.value
        })
    },
    //ocr性别赋值
    ocrSexInput: function (e) {
        this.setData({
            ocrSex: e.detail.value
        })
    },
    //ocr民族赋值
    ocrNationInput: function (e) {
        this.setData({
            ocrNation: e.detail.value
        })
    },
    //ocr出生赋值
    ocrBirthInput: function (e) {
        this.setData({
            ocrBirth: e.detail.value
        })
    },
    //ocr地址赋值
    ocrAddressInput: function (e) {
        this.setData({
            ocrAddress: e.detail.value
        })
    },
    //ocr身份证号
    ocrIdNumberInput: function (e) {
        this.setData({
            ocrIdNumber: e.detail.value
        })
    },
    //ocr发证机关
    ocrOfficeInput: function (e) {
        this.setData({
            ocrOffice: e.detail.value
        })
    },
    //ocr有效期限
    ocrValidityPeriodInput: function (e) {
        this.setData({
            ocrValidityPeriod: e.detail.value
        })
    },

    //品牌/车型
    brandInput: function (e) {
        this.setData({
            brand: e.detail.value
        })
    },
    //车牌号
    plateNumberInput: function (e) {
        this.setData({
            plateNumber: e.detail.value
        })
    },
    //所有人
    holderInput: function (e) {
        this.setData({
            holder: e.detail.value
        })
    },
    //注册/发证日期
    dateIssueInput: function (e) {
        this.setData({
            dateIssue: e.detail.value
        })
    },
    //使用性质
    natureInput: function (e) {
        this.setData({
            nature: e.detail.value
        })
    },
    //住址
    addressInput: function (e) {
        this.setData({
            address: e.detail.value
        })
    },
    //车架号
    vinnoInput: function (e) {
        this.setData({
            vinno: e.detail.value
        })
    },
    //发动机号
    engineNumberInput: function (e) {
        this.setData({
            engineNumber: e.detail.value
        })
    },
    orderBy6Input: function (e) {
        this.setData({
            orderBy6: e.detail.value
        })
    },
    //
    orderBy7Input: function (e) {
        this.setData({
            orderBy7: e.detail.value
        })
    },  //
    orderBy8Input: function (e) {
        this.setData({
            orderBy8: e.detail.value
        })
    },
    //储蓄卡
    orderBy9Input: function (e) {
        this.setData({
            orderBy9: e.detail.value
        })
    },
    //开户行
    orderBy10Input: function (e) {
        this.setData({
            orderBy10: e.detail.value
        })
    },
    //银行预留电话
    orderBy11Input: function (e) {
        this.setData({
            orderBy11: e.detail.value
        })
    }, 
    upEnclosure: function (e) {
        var that = this;
        var sbtype = e.currentTarget.dataset.sbtype
        wx.chooseImage({
            count: 1, //最多可以选择的图片总数  
            sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有  
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有  
            success: function (res) {
                // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片  
                var tempFilePaths = res.tempFilePaths;
                //启动上传等待中...  
                wx.showToast({
                    title: '正在上传...',
                    icon: 'loading',
                    mask: true,
                    duration: 20000
                })
                var uploadImgCount = 0;
                for (var i = 0, h = tempFilePaths.length; i < h; i++) {
                    wx.uploadFile({
                        url: pathUrl + '/rest/base/uploadsb',
                        filePath: tempFilePaths[i],
                        name: 'uploadfile_ant',
                        formData: {
                            sbtype: sbtype,
                            filetype: 'sb',
                            orderNo: that.data.orderNo
                        },
                        header: {
                            "Content-Type": "multipart/form-data"
                        },
                        success: function (res) {
                            uploadImgCount++;
                            console.log(res);
                            if (sbtype == 2) {
                                var data = JSON.parse(res.data);
                                data = JSON.parse(data[0].piccontent);
                                var items = data.result.cardsinfo[0].items;
                                console.log(data.result.cardsinfo[0].items)
                                that.setData({
                                    ocrName: items[1].content,
                                    ocrSex: items[2].content,
                                    ocrNation: items[3].content,
                                    ocrBirth: items[4].content,
                                    ocrAddress: items[5].content,
                                    ocrIdNumber: items[6].content,
                                })
                                console.log("sbtype == 2:" + JSON.stringify(items))
                            } else if (sbtype == 3) {
                                var data = JSON.parse(res.data);
                                data = JSON.parse(data[0].piccontent);
                                var items = data.result.cardsinfo[0].items;
                                that.setData({
                                    ocrOffice: items[1].content,
                                    ocrValidityPeriod: items[2].content,
                                    cusIdValidfrom: items[3].content,
                                    cusIdValidto: items[4].content
                                })
                                console.log("sbtype == 3:" + JSON.stringify(items))

                            } else if (sbtype == 6) {
                                console.log(data.result.cardsinfo[0].items)
                                var data = JSON.parse(res.data);
                                data = JSON.parse(data[0].piccontent);
                                var items = data.result.cardsinfo[0].items;
                                that.setData({
                                    brand: items[5].content,
                                    plateNumber: items[1].content,
                                    holder: items[3].content,
                                    dateIssue: items[8].content,
                                    nature: items[10].content,
                                    address: items[4].content,
                                    vinno: items[6].content,
                                    engineNumber: items[7].content,
                                })
                                console.log("sbtype == 6:" + JSON.stringify(items))
                            } else if (sbtype == 5) {
                                var data = JSON.parse(res.data);
                                data = JSON.parse(data[0].piccontent);
                                var items = data.result.cardsinfo[0].items;
                                that.setData({
                                    holder: items[2].content,
                                    dateIssue: items[6].content,
                                    nature: items[7].content,
                                    address: items[4].content,

                                })
                                console.log(data);
                                console.log(items);
                            }
                            if (uploadImgCount == tempFilePaths.length) {
                                wx.hideToast();
                            }
                        },
                        fail: function (res) {
                            wx.hideToast();
                            wx.showModal({
                                title: '错误提示',
                                content: '上传图片失败',
                                showCancel: false
                            })
                        }
                    });
                }
            }
        });
    },
  submitBtn: function () {
    var that = this;
    console.log("name" + that.data.ocrName)
    console.log("cardid" + that.data.ocrIdNumber)
      console.log("百融")
      wx.request({
        url: pathUrl + '/rest/fk/dobairongstr',
        data: {
          realName: that.data.realname,
          cardNo: that.data.cardId,
          bankCardNo: that.data.bankcardno,
          mobile: that.data.mobile,

        },
        method: 'POST',
        success: function (res) {
          console.log(res)
          console.log(typeof (res.data.data.rmContent))
          var str = res.data.data.rmContent,
            arr = str.split(",");
          console.log(str);
          console.log(arr);
          console.log(typeof (arr[2]));
          console.log(arr[2]);
          var str1 = arr[2];
          var arr1 = str1.split(':');
          console.log(typeof (arr1))
          console.log(arr1)
          console.log(arr1[4])
          if (res.data.ok) {
            that.setData({
              queryResults: res.data.data.rmBy7,//查询结果
              violationTimes: arr1[4],//信用分数

            })
          }
          else {
            wx.showModal({
              title: '提示',
              content: '获取数据失败',
              confirmColor: '#7aa6d1',
              showCancel: false
            })
          }
        }
      })
    
  },
    // submitBtn: function () {
    //     var that = this;
    //     console.log("name" + that.data.ocrName)
    //     console.log("cardid" + that.data.ocrIdNumber)
    //     if (that.data.index == 0) {
    //         console.log("同盾")
    //         wx.request({
    //             url: pathUrl + '/rest/fk/dotongdun',
    //             data: {
    //                 realName: that.data.ocrName,
    //                 cardNo: that.data.ocrIdNumber,
    //                 bankCardNo: that.data.bankcardno,
    //                 mobile: that.data.mobile,

    //             },
    //             method: 'POST',
    //             success: function (res) {
    //                 console.log(res)
    //                 console.log(typeof (res.data.data.rmContent))
    //                 var str = res.data.data.rmContent,
    //                     arr = str.split(",");
    //                     console.log(str);
    //                     console.log(arr);
    //                     console.log(typeof(arr[2]));
    //                     console.log(arr[2]);
    //                 var  str1 =arr[2];
    //                 var  arr1  =str1.split(':');
    //                 console.log(typeof (arr1))
    //                     console.log(arr1)
    //                     console.log(arr1[4])
    //                 if (res.data.ok) {
    //                     // wx.showModal({
    //                     //     title: '提示',
    //                     //     content: "查询"+ res.data.message,
    //                     //     showCancel: false
    //                     // })
    //                     that.setData({
    //                         queryResults: res.data.data.rmBy7,//查询结果
    //                         violationTimes:arr1[4],//信用分数

    //                     })
    //                 } else {
    //                     wx.showModal({
    //                         title: '提示',
    //                         content: '获取数据失败',
    //                         confirmColor: '#7aa6d1',
    //                         showCancel: false
    //                     })
    //                 }
    //             }
    //         })
    //     } 
    //     else if (that.data.index == 1){
    //         console.log("百融")
    //         wx.request({
    //             url: pathUrl + '/rest/fk/dobairongstr',
    //             data: {
    //                 realName: that.data.realname,
    //                 cardNo: that.data.cardId,
    //                 bankCardNo: that.data.bankcardno,
    //                 mobile: that.data.mobile,

    //             },
    //             method: 'POST',
    //             success: function (res) {
    //                 console.log(res)
    //                 console.log(typeof (res.data.data.rmContent))
    //                 var str = res.data.data.rmContent,
    //                  arr = str.split(",");
    //                 console.log(str);
    //                 console.log(arr);
    //                 console.log(typeof (arr[2]));
    //                 console.log(arr[2]);
    //                 var str1 = arr[2];
    //                 var arr1 = str1.split(':');
    //                 console.log(typeof (arr1))
    //                 console.log(arr1)
    //                 console.log(arr1[4])
    //                 if (res.data.ok) {
    //                     that.setData({
    //                         queryResults: res.data.data.rmBy7,//查询结果
    //                         violationTimes: arr1[4],//信用分数

    //                     })
    //                 } 
                    
    //             }
    //         })
    //     }
    //     else if (that.data.index == 2) {
    //         console.log("中诚信")
    //         wx.request({
    //             url: pathUrl + '/rest/fk/dozcx',
    //             data: {
    //                 realName: that.data.realname,
    //                 cardNo: that.data.cardId,
    //                 // bankCardNo: that.data.bankcardno,
    //                 mobile: that.data.mobile,

    //             },
    //             method: 'POST',
    //             success: function (res) {
    //                 console.log(res)
    //                 console.log(typeof (res.data.data.rmContent))
    //                 // var str = res.data.data.rmContent,
    //                 //     arr = str.split(",");
    //                 // console.log(str);
    //                 // console.log(arr);
    //                 // console.log(typeof (arr[2]));
    //                 // console.log(arr[2]);
    //                 // var str1 = arr[2];
    //                 // var arr1 = str1.split(':');
    //                 // console.log(typeof (arr1))
    //                 // console.log(arr1)
    //                 // console.log(arr1[4])
    //                 if (res.data.ok) {
    //                     that.setData({
    //                         // queryResults: res.data.data.rmBy7,//查询结果
    //                         // violationTimes: arr1[4],//信用分数

    //                     })
    //                 }

    //             }
    //         })
    //     }
    //     else {
    //     wx.showModal({
    //         title: '提示',
    //         content: '获取数据失败',
    //         confirmColor: '#7aa6d1',
    //         showCancel: false
    //     })
    //     }
    // },
    // submitBtn1: function () {
    //     var that = this;
    //     console.log("name" + that.data.ocrName)
    //     console.log("cardid" + that.data.ocrIdNumber)
    //     if (that.data.index == 3) {
    //         console.log("黑瞳逾期")
    //         wx.request({
    //             url: pathUrl + '/rest/fk/doyqbq',
    //             data: {
    //                 realName: that.data.ocrName,
    //                 cardNo: that.data.ocrIdNumber,
    //                 bankCardNo: that.data.bankcardno,
    //                 mobile: that.data.mobile,

    //             },
    //             method: 'POST',
    //             success: function (res) {
    //                 console.log(res)
    //                 console.log(typeof (res.data.data.rmContent))
    //                 // var str = res.data.data.rmContent,
    //                 //     arr = str.split(",");
    //                 // console.log(str);
    //                 // console.log(arr);
    //                 // console.log(typeof (arr[2]));
    //                 // console.log(arr[2]);
    //                 // var str1 = arr[2];
    //                 // var arr1 = str1.split(':');
    //                 // console.log(typeof (arr1))
    //                 // console.log(arr1)
    //                 // console.log(arr1[4])
    //                 if (res.data.ok) {
    //                     // that.setData({
    //                     //     queryResults: res.data.data.rmBy7,//查询结果
    //                     //     violationTimes: arr1[4],//信用分数

    //                     // })
    //                 } else {
    //                     wx.showModal({
    //                         title: '提示',
    //                         content: '获取数据失败',
    //                         confirmColor: '#7aa6d1',
    //                         showCancel: false
    //                     })
    //                 }
    //             }
    //         })
    //     }
    //     else {
    //         wx.showModal({
    //             title: '提示',
    //             content: '获取数据失败',
    //             confirmColor: '#7aa6d1',
    //             showCancel: false
    //         })
    //     }
    // },
    // submitBtn2: function () {
    //     var that = this;
    //     console.log("name" + that.data.ocrName)
    //     console.log("cardid" + that.data.ocrIdNumber)
    //     if (that.data.index == 3) {
    //         console.log("共债通用")
    //         wx.request({
    //             url: pathUrl + '/rest/fk/dogzty"',
    //             data: {
    //                 realName: that.data.ocrName,
    //                 cardNo: that.data.ocrIdNumber,
    //                 bankCardNo: that.data.bankcardno,
    //                 mobile: that.data.mobile,

    //             },
    //             method: 'POST',
    //             success: function (res) {
    //                 console.log(res)
    //                 console.log(typeof (res.data.data.rmContent))
    //                 // var str = res.data.data.rmContent,
    //                 //     arr = str.split(",");
    //                 // console.log(str);
    //                 // console.log(arr);
    //                 // console.log(typeof (arr[2]));
    //                 // console.log(arr[2]);
    //                 // var str1 = arr[2];
    //                 // var arr1 = str1.split(':');
    //                 // console.log(typeof (arr1))
    //                 // console.log(arr1)
    //                 // console.log(arr1[4])
    //                 if (res.data.ok) {
    //                     // that.setData({
    //                     //     queryResults: res.data.data.rmBy7,//查询结果
    //                     //     violationTimes: arr1[4],//信用分数

    //                     // })
    //                 } else {
    //                     wx.showModal({
    //                         title: '提示',
    //                         content: '获取数据失败',
    //                         confirmColor: '#7aa6d1',
    //                         showCancel: false
    //                     })
    //                 }
    //             }
    //         })
    //     }
    //     else {
    //         wx.showModal({
    //             title: '提示',
    //             content: '获取数据失败',
    //             confirmColor: '#7aa6d1',
    //             showCancel: false
    //         })
    //     }
    // },
    // submitBtn3: function () {
    //     var that = this;
    //     console.log("name" + that.data.ocrName)
    //     console.log("cardid" + that.data.ocrIdNumber)
    //     if (that.data.index == 3) {
    //         console.log("综合数据")
    //         wx.request({
    //             url: pathUrl + '/rest/fk/dozhbq',
    //             data: {
    //                 realName: that.data.ocrName,
    //                 cardNo: that.data.ocrIdNumber,
    //                 bankCardNo: that.data.bankcardno,
    //                 mobile: that.data.mobile,

    //             },
    //             method: 'POST',
    //             success: function (res) {
    //                 console.log(res)
    //                 console.log(typeof (res.data.data.rmContent))
    //                 // var str = res.data.data.rmContent,
    //                 //     arr = str.split(",");
    //                 // console.log(str);
    //                 // console.log(arr);
    //                 // console.log(typeof (arr[2]));
    //                 // console.log(arr[2]);
    //                 // var str1 = arr[2];
    //                 // var arr1 = str1.split(':');
    //                 // console.log(typeof (arr1))
    //                 // console.log(arr1)
    //                 // console.log(arr1[4])
    //                 if (res.data.ok) {
    //                     // that.setData({
    //                     //     queryResults: res.data.data.rmBy7,//查询结果
    //                     //     violationTimes: arr1[4],//信用分数

    //                     // })
    //                 } else {
    //                     wx.showModal({
    //                         title: '提示',
    //                         content: '获取数据失败',
    //                         confirmColor: '#7aa6d1',
    //                         showCancel: false
    //                     })
    //                 }
    //             }
    //         })
    //     }
    //     else {
    //         wx.showModal({
    //             title: '提示',
    //             content: '获取数据失败',
    //             confirmColor: '#7aa6d1',
    //             showCancel: false
    //         })
    //     }
    // },

    

    
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (e) {
        var openId = wx.getStorageSync('openId');
      var ocrName =e.name;
      var ocrIdNumber = e.ocrIdNumber;
        console.log(e)
        this.setData({
            openId: openId,
            ocrName: ocrName,
          ocrIdNumber: ocrIdNumber
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})